/* Header de la lib td (Tiny Database).
   Version 0.2.8 */

#define byte char
#ifndef uint
#define uint unsigned int
#endif

enum {INVALID_SESSION = 2, ALREADY_EXIST, INVALID_ROW, INVALID_SUBBASE, INVALID_BASE, INVALID_MODE, INVALID_CASE};
enum {ROW_NOT_EXIST = 8, SUBBASE_NOT_EXIST, BASE_NOT_EXIST, INVALID_STRING, CANT_WRITE};

enum {SELECTED = 2, GET, SELECT, NO_SELECT, O_AUTO, O_MANUAL, O_VIRTUAL, CASE_SENS, NO_CASE_SENS};

typedef struct _td_row td_row;
struct _td_row
{
  char *ident;
  char *val;
  byte issub;
};

extern const uint td_err;
extern const char *tdversion;

int td_init (char *path);
void td_free_row (td_row *k);
char *td_error (uint nid, char *lang);
void td_clean (void);

unsigned int td_select_base (char *se);
td_row *td_select_subbase (unsigned int si, char *se);
td_row *td_select_subbase_p (unsigned int si, char *buffer, char delim);
td_row *td_select_subbase_r (unsigned int si, int *nerr, ...);
td_row *td_select_row (unsigned int si, char *se);
td_row *td_select_row_p (unsigned int si, char *buffer, char delim);
td_row *td_select_row_r (unsigned int si, int *nerr, char *srow, ...);
td_row *td_select_next_row (unsigned int si);
td_row *td_select_next_subbase (unsigned int si);
td_row *td_select_first_subbase (unsigned int si);
td_row *td_select_first_row (unsigned int si);
td_row *td_select_parent_subbase (unsigned int si);

byte td_add_row (unsigned int si, char *id, char *va, byte mode);
byte td_add_subbase (unsigned int si, char *id, byte mode);
uint td_add_base (char *se, byte c_s, byte o_mode);

byte td_del_subbase (unsigned int si, char *id, byte mode);
byte td_del_subbase_p (unsigned int si, char *id, char delim);
byte td_del_row (unsigned int si, char *id, byte mode);
byte td_del_base (unsigned int si, char *id, byte mode);

byte td_update_val_row_p (unsigned int si, char *se, char delim, char *nval);
byte td_update_val_row (unsigned int si, char *se, char *nval, byte mode);
byte td_update_ident_row_p (unsigned int si, char *se, char delim, char *nid);
byte td_update_ident_row (unsigned int si, char *se, char *nid, byte mode);
byte td_update_ident_subbase (unsigned int si, char *nid);

unsigned int td_new_session (unsigned int si);
byte td_close_session (uint si);
unsigned int td_open_base (char *se, byte c_s, byte mode);
byte td_write_base (uint si);
byte td_close_base (uint si);
byte td_print_base (unsigned int si);
